﻿#include<stdio.h>
#include<iostream>
#include<assert.h>
using namespace std;
void test01() {
	short a = 3;
	long long b = 4;
	printf("%d\n", sizeof(a = b + 4));
	printf("%d\n", a);
}
void test02() {
	char ch[3] = { 'a','b','c' };
	size_t len = strlen(ch);
	//size_t len1 = strlen(*ch);
	printf("%d", len);
}


//islower 判断是否为小写字母
void test03() {
	int ret = islower('a');
	printf("%d\n", ret);
	ret = islower('b');
	printf("%d\n", ret);
	ret = islower('A');
	printf("%d\n", ret);
	ret = islower('1');
	printf("%d\n", ret);
}
//islower 判断是否为小写字母


//将小写字母转换为大写字母
//小写字母的asc码值减去32对应的是大写字母的asc码值
void test04() {
	char ch[] = "I am a Student";
	for (int i = 0; i < strlen(ch); i++) {
		if (islower(ch[i])) {
			ch[i] = ch[i] - 32;
		}
	}
	printf("%s", ch);
}
//将小写字母转换为大写字母



//字符分类函数都在 ctype 库中



//strlen的模拟实现
size_t my_strlen_1(const char* str) {
	assert(str != NULL);
	size_t count = 0;
	while (*str != '\0') {
		count++;
		str++;
	}
	return count;
}
size_t my_strlen_2(const char* str) {
	assert(str != NULL);
	const char* start = str;
	while (*str != '\0') {
		str++;
	}
	return str - start;
}
size_t my_strlen_3(const char* str) {
	assert(str != NULL);
	if (*str != '\0')
		return 1 + my_strlen_3(++str);
	else
		return 0;
}
//strlen模拟实现


//strcpy模拟实现
char* my_strcpy(char* des, const char* src) {
	assert(des && src);
	char* start = des;
	while (*des++ = *src++);
	return start;
}
//strcpy模拟实现


//strcat模拟实现
char* my_strcat(char* des, const char* src) {
	assert(des && src);
	char* ret = des;
	while (*des != '\0') {
		des++;
	}
	while (*des++ = *src++);
	return ret;
}
//strcat模拟实现


//strcmp模拟实现
int my_strcmp(const char* des, const char* src) {
	assert(des && src);
	while (*des == *src) {
		if (*des == '\0') return 0;
		des++;
		src++;
	}
	return *des - *src;
}
//strcmp模拟实现

int main() {
	//test01();
	//test02();
	//test03();
	//test04();
	/*char ch[4] = "abc";
	printf("%zd\n", my_strlen_1(ch));
	printf("%zd\n", my_strlen_2(ch));
	printf("%zd\n", my_strlen_3(ch));*/
	char arr1[5] = "abc ";
	char arr2[20] = { 0 };
	char arr3[20] = "abc";
	//printf("%s",my_strcpy(arr2, arr1));
	//printf("%s", my_strcat(arr3, arr1));
	printf("%d", my_strcmp(arr1, arr3));
	return 0;
}